import { cloneDeep } from "lodash";

export default {
  /** 设置异步间隔延迟
   * @param {Number} interval 延迟时间
   * @return {Promise} 延迟结束
   * */
  delay(interval = 0) {
    return new Promise((resolve) => {
      let timer = setTimeout(() => {
        clearTimeout(timer);
        resolve();
      }, interval);
    });
  },
  /**对象解构赋值
   * @param {Object} originObj 解构对象
   * @param {Array} keyArr 需要解构的key
   */
  pick(originObj, keyArr) {
    return keyArr.reduce(
      (total, val) => (
        val in originObj && (total[val] = originObj[val]), total
      ),
      {}
    );
  },

  /**判断对象是否为空
   * @param {Object} obj 需要做判断的对象
   * @return {Boolean} 是否为空
   * */
  isEmptyObj(obj = {}) {
    return Object.keys(obj) && Object.keys(obj).length === 0;
  },
  /** 复制到剪切板
   * @param {String} text 复制的文字
   * */
  copyToClipboard(text) {
    navigator.clipboard && navigator.clipboard.write(text);
  },
};
